<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="120px">
      <el-form-item label="一级销区名称" prop="rp02name">
        <el-input
          v-model="queryParams.rp02name"
          placeholder="请输入一级销区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级销区名称" prop="rp03name">
        <el-input
          v-model="queryParams.rp03name"
          placeholder="请输入二级销区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="店面名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入店面名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经营模式" prop="manageMode">
        <el-input
          v-model="queryParams.manageMode"
          placeholder="请输入门店经营模式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="修改来源" prop="updateSource">
        <el-select v-model="queryParams.updateSource" placeholder="请选择修改来源">
          <el-option
            v-for="dict in sourceList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="修改类型" prop="updateType">
        <el-select v-model="queryParams.updateType" placeholder="请选择修改类型">
          <el-option
            v-for="dict in typeList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="反馈人员HN号" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输反馈人员HN号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="createName">
        <el-input
          v-model="queryParams.createName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更正时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.createTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button 
          type="primary" 
          icon="el-icon-search" 
          size="mini" 
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" border stripe :data="storeBasicsList" @selection-change="handleSelectionChange">
      <el-table-column label="一级销区名称" align="center" prop="rp02name" />
      <el-table-column label="二级销区名称" align="center" prop="rp03name" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="店面名称" align="center" prop="storeName" />
      <el-table-column label="经营模式" align="center" prop="manageMode" />
      <el-table-column label="修改来源" align="center" prop="updateSource" />
      <el-table-column label="修改类型" align="center" prop="updateType" />
      <el-table-column label="原数据" align="center" prop="oldData" />
      <el-table-column label="更正数据" align="center" prop="newData" />
      <el-table-column label="更正时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="反馈人员HN号" align="center" prop="createBy" />
      <el-table-column label="姓名" align="center" prop="createName" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { getFeedback, exportFeedback } from "@/api/xdstore/storeBasics";

export default {
  name: "StoreBasics",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 门店基础信息表格数据
      storeBasicsList: [],
      // 是否有效字典
      isActiveOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rp02name: undefined,
        rp03name: undefined,
        brand: undefined,
        storeName: undefined,
        manageMode: undefined,
        updateSource: undefined,
        updateType: undefined,
        createBy: undefined,
        createName: undefined,     
        createTime: undefined,    
      },
      sourceList:[
        {value: '助店', label:'助店'}
      ],
      typeList:[
        {value: '店面类型', label:'店面类型'}
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  activated() {

  },
  methods: {
    /** 查询门店基础信息列表 */
    getList() {
      this.loading = true;
      const params = {...this.queryParams}
      if(params.createTime){
        if(params.createTime[0] && params.createTime[1]) {
          params.beginTime = params.createTime[0] + ' 00:00:00'
          params.endTime = params.createTime[1] + ' 23:59:59'
        }
        delete params.createTime
      }
      getFeedback(params).then(response => {
        this.storeBasicsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否有效字典翻译
    isActiveFormat(row, column) {
      return this.selectDictLabel(this.isActiveOptions, row.isActive);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery(){
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有店面信息异常反馈表', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportFeedback(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>

<style>
.el-date-range-picker__time-header{
  display: none
}
</style>
